<?php

class Lib_Notice{

    //通用的响应码和信息
    private static $global_resposne = array(
        200  => 'Success',
        404  => 'Not found',
        500  => 'Internal error',
        503  => 'Service unavailable',
        4000 => 'Operate failed',
        4001 => 'Missing necessary parameters',
        4002 => 'Invalid Appid',
        4003 => 'Signkey check failed',
        4004 => 'Request expired',
        4005 => 'Access denied',
        4006 => 'Invalid parameters',
        4007 => 'Invalid utf-8 encoding',
        4008 => 'Invalid data format',
        4009 => 'No data submission',
        4010 => 'Data decrypt failed',
        4011 => 'api not found',
        4012 => 'Repeating data',
        4013 => 'Decryption failed',
    );

    public static function response($code,$message = '',$data = []){
        return array(
            'code' => $code,
            'message' => empty($message) ? isset(self::$global_resposne[$code]) ? self::$global_resposne[$code] : '' : $message,
            'data'=>$data,
        );
    }


    public static function checkData($data,$fields){
        $check = true;
        foreach($fields as $val){
            if(empty($data[$val])){
                $check = false;
                break;
            }
            $data[$val] = $data[$val];
        }
        return $check;
    }
}